package org.eweb4j.config;

import org.eweb4j.cache.SingleBeanCache;
import org.eweb4j.config.bean.ConfigBean;
import org.eweb4j.ioc.config.IOCLogger;
import org.eweb4j.mvc.config.MVCLogger;
import org.eweb4j.orm.ORMLogger;


public class LogFactory {
	public static Logger getIOCLogger(String level) {
		ConfigBean cb = (ConfigBean) SingleBeanCache
				.get(ConfigConstant.CONFIGBEAN_ID);

		String filePath = cb == null ? "" : ConfigConstant.CONFIG_BASE_PATH
				+ cb.getIoc().getLogFile();
		String maxSize = cb == null ? "5" : cb.getIoc().getLogMaxSize();
		String debug = cb == null ? "false" : cb.getIoc().getDebug();
		boolean isDebug = false;
		if ("true".equalsIgnoreCase(debug) || "1".equalsIgnoreCase(debug))
			isDebug = true;

		return new IOCLogger(isDebug, level, filePath,
				Integer.parseInt(maxSize));
	}

	public static Logger getMVCLogger(String level) {
		ConfigBean cb = (ConfigBean) SingleBeanCache
				.get(ConfigConstant.CONFIGBEAN_ID);

		String filePath = cb == null ? "" : ConfigConstant.CONFIG_BASE_PATH
				+ cb.getMvc().getLogFile();
		String maxSize = cb == null ? "5" : cb.getMvc().getLogMaxSize();
		String debug = cb == null ? "false" : cb.getMvc().getDebug();
		boolean isDebug = false;
		if ("true".equalsIgnoreCase(debug) || "1".equalsIgnoreCase(debug))
			isDebug = true;

		return new MVCLogger(isDebug, level, filePath,
				Integer.parseInt(maxSize));
	}

	public static Logger getORMLogger(String level) {
		ConfigBean cb = (ConfigBean) SingleBeanCache
				.get(ConfigConstant.CONFIGBEAN_ID);

		String filePath = cb == null ? "" : ConfigConstant.CONFIG_BASE_PATH
				+ cb.getOrm().getLogFile();
		String maxSize = cb == null ? "5" : cb.getOrm().getLogMaxSize();

		String debug = cb == null ? "false" : cb.getOrm().getDebug();
		boolean isDebug = false;
		if ("true".equalsIgnoreCase(debug) || "1".equalsIgnoreCase(debug))
			isDebug = true;
		return new ORMLogger(isDebug, level, filePath,
				Integer.parseInt(maxSize));
	}

	public static Logger getConfigLogger(String level) {
		// TODO Auto-generated method stub
		boolean isDebug = true;
		
		return new ConfigLogger(isDebug, level);
	}
}
